<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => ['required', 'between:2,50'],
            'mobile' => ['required'],
            'idcard' => ['required'],
            'gender' => ['required'],
            'birthday' => ['required'],
            'is_submit' => ['required']
        ];
    }

    public function messages()
    {
        return [
            'name.required' => '姓名不能为空。',
            'name.between' => '姓名必须介于2-50个字符之间。',
            'idcard.required' => '请填写证件号码。',
            'gender.required' => '请选择性别。',
            'mobile.required' => '请填写手机号码。',
            'birthday.required' => '请填写出生日期。',
            'is_submit.required' => '防止AJAX验证数据而误将数据保存进数据库。'
        ];
    }
}
